package cz.proks.easyhelpdesk.gwt.ui.widget;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.DomEvent;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;

import cz.proks.easyhelpdesk.gwt.event.HasLeftArrowClickHandlers;
import cz.proks.easyhelpdesk.gwt.event.LeftArrowClickEvent;
import cz.proks.easyhelpdesk.gwt.event.LeftArrowClickEvent.Handler;


public class LeftArrowHyperlinkButton extends AGraphicHyperlinkButton implements HasLeftArrowClickHandlers {

    @SuppressWarnings("deprecation")
    public LeftArrowHyperlinkButton() {
        super();
     
        setStyleName(getResources().style().leftarrowButton());
        addClickHandler(new ClickHandler() {
            
            @Override
            public void onClick(ClickEvent event) {                
                event.preventDefault();                                      
                fireEvent(new LeftArrowClickEvent());
            }
        });
    }      
    
    @Override
    public void onBrowserEvent(Event event) {             
        DomEvent.fireNativeEvent(event, this, this.getElement());
        
        if (DOM.eventGetType(event) == Event.ONCLICK)
            event.preventDefault();
    }
    
    @Override
    public HandlerRegistration addLeftArrowClickHandler(Handler handler) {        
        return addHandler(handler, LeftArrowClickEvent.TYPE);
    }
}
